package com.ruoyi.web.controller.enterprise;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.enterprise.domain.SewagePermit;
import com.ruoyi.enterprise.service.ISewagePermitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 排污许可证Controller
 * 
 * @author yxf
 * @date 2021-09-14
 */
@RestController
@RequestMapping("/enterprise/permit")
public class SewagePermitController extends BaseController
{
    @Autowired
    private ISewagePermitService sewagePermitService;

    /**
     * 查询排污许可证列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:permit:list')")
    @GetMapping("/list")
    public TableDataInfo list(SewagePermit sewagePermit)
    {
        startPage();
        List<SewagePermit> list = sewagePermitService.selectSewagePermitList(sewagePermit);
        return getDataTable(list);
    }

    /**
     * 导出排污许可证列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:permit:export')")
    @Log(title = "排污许可证", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SewagePermit sewagePermit)
    {
        List<SewagePermit> list = sewagePermitService.selectSewagePermitList(sewagePermit);
        ExcelUtil<SewagePermit> util = new ExcelUtil<SewagePermit>(SewagePermit.class);
        return util.exportExcel(list, "排污许可证数据");
    }

    /**
     * 获取排污许可证详细信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:permit:query')")
    @GetMapping(value = "/{swId}")
    public AjaxResult getInfo(@PathVariable("swId") Long swId)
    {
        return AjaxResult.success(sewagePermitService.selectSewagePermitById(swId));
    }

    /**
     * 新增排污许可证
     */
    @PreAuthorize("@ss.hasPermi('enterprise:permit:add')")
    @Log(title = "排污许可证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SewagePermit sewagePermit)
    {
        return toAjax(sewagePermitService.insertSewagePermit(sewagePermit));
    }

    /**
     * 修改排污许可证
     */
    @PreAuthorize("@ss.hasPermi('enterprise:permit:edit')")
    @Log(title = "排污许可证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SewagePermit sewagePermit)
    {
        return toAjax(sewagePermitService.updateSewagePermit(sewagePermit));
    }

    /**
     * 删除排污许可证
     */
    @PreAuthorize("@ss.hasPermi('enterprise:permit:remove')")
    @Log(title = "排污许可证", businessType = BusinessType.DELETE)
	@DeleteMapping("/{swIds}")
    public AjaxResult remove(@PathVariable Long[] swIds)
    {
        return toAjax(sewagePermitService.deleteSewagePermitByIds(swIds));
    }
}
